package com.hhit.bigscreenbackmanage.service.impl.tgygl;

import com.alibaba.fastjson.JSONObject;
import com.hhit.bigscreenbackmanage.dao.tgygl.TTgyglKeyWorkMapper;
import com.hhit.bigscreenbackmanage.entity.tgygl.TTgyglKeyWork;
import com.hhit.bigscreenbackmanage.service.tgygl.TTgyglKeyWorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class TTgyglKeyWorkServiceImpl implements TTgyglKeyWorkService {

    @Autowired
    private TTgyglKeyWorkMapper tTgyglKeyWorkMapper;

    @Override
    public List<TTgyglKeyWork> getTTgyglKeyWork(JSONObject json) throws Exception{
        return tTgyglKeyWorkMapper.getTTgyglKeyWork(json);
    }

    @Override
    public JSONObject getGZDPTj(JSONObject json) {
        return tTgyglKeyWorkMapper.getGZDPTj(json);
    }

    @Override
    public int insertTTgyglKeyWork(JSONObject json) throws Exception{
        List<TTgyglKeyWork> list = JSONObject.parseArray(JSONObject.toJSONString(json.get("list")), TTgyglKeyWork.class);
        int result = 0;
        if (!list.isEmpty()) {
            list.forEach(t -> {
                t.setId(UUID.randomUUID().toString().replaceAll("-", "").toUpperCase());
            });
            result = tTgyglKeyWorkMapper.insertTTgyglKeyWork(list);
        }
        return result;
    }
}
